home *** CD-ROM | disk | FTP | other *** search
/ Graphics & Sound Program…ng Techniques for the Mac / Graphics and Sound Programming Techniques for the Mac.iso / M&T Graphics & Sound Examples / Symantec Versions / C07 QuickTime Movies / P05 Movie Looping / MovieLooping.c next >
Encoding:
C/C++ Source or Header  |  1995-08-31  |  3.1 KB  |  123 lines  |  [TEXT/KAHL]

  1. //____________________________________________________________
  2. //    MovieLooping.c
  3. //
  4. //    Copyright © Dan Parks Sydow, 1995
  5. //    From the book:
  6. //    "Graphics and Sound Programming Techniques for the Mac",
  7. //    M&T Books, 1995
  8.  
  9.  
  10. //____________________________________________________________
  11.  
  12. #include <Movies.h>   
  13.  
  14.  
  15. //____________________________________________________________
  16.  
  17. void  InitializeAllToolboxes( void );
  18.  
  19.  
  20. //____________________________________________________________
  21.  
  22. #define      rMovieWindow           128
  23. #define      kMovieName        "\pRobot"
  24.  
  25.  
  26. //____________________________________________________________
  27.  
  28. void  main( void )
  29.    OSErr            theError;
  30.    FSSpec           theFSSpec;
  31.    short            theFileRefNum;
  32.    Movie            theMovie;
  33.    short            theMovieResID = 0;   
  34.    Str255           theMovieResName;
  35.    Boolean          wasAltered;
  36.    WindowPtr        theWindow;
  37.    Rect             theMovieBox;
  38.    Rect             theBoundsRect;
  39.    MovieController  theController = nil;
  40.    EventRecord      theEvent;
  41.    Boolean          isControllerEvent;
  42.    Boolean          allDone = false;
  43.  
  44.    InitializeAllToolboxes();
  45.    
  46.    theError = FSMakeFSSpec( 0, 0, kMovieName, &theFSSpec );
  47.    theError = OpenMovieFile( &theFSSpec, &theFileRefNum, fsRdPerm );
  48.    theError = NewMovieFromFile( &theMovie, theFileRefNum, &theMovieResID,
  49.                                  theMovieResName, newMovieActive, &wasAltered );
  50.                                          
  51.    CloseMovieFile( theFileRefNum );
  52.    
  53.    theWindow = GetNewCWindow( rMovieWindow, nil, (WindowPtr)-1L );   
  54.  
  55.    SetMovieGWorld( theMovie, (CGrafPtr)theWindow, nil );   
  56.  
  57.    GetMovieBox( theMovie, &theMovieBox );
  58.  
  59.    theController = NewMovieController( theMovie, &theMovieBox, mcTopLeftMovie);   
  60.  
  61.    MCDoAction( theController, mcActionSetLooping, (Ptr)true );  // ** NEW CODE **
  62.  
  63.    MCGetControllerBoundsRect( theController, &theBoundsRect );
  64.  
  65.    SizeWindow( theWindow, theBoundsRect.right, theBoundsRect.bottom, true );  
  66.    ShowWindow( theWindow );
  67.  
  68.    while ( allDone == false )
  69.    {
  70.       WaitNextEvent( everyEvent, &theEvent, 15L, nil );
  71.       
  72.       if ( theController == nil )
  73.          isControllerEvent = false;
  74.       else
  75.          isControllerEvent = MCIsPlayerEvent( theController, &theEvent );
  76.       
  77.       if ( isControllerEvent == false )
  78.       {
  79.          switch ( theEvent.what )
  80.          {
  81.             case keyDown:
  82.                allDone = true;
  83.                break;
  84.          }
  85.       }
  86.    }
  87.  
  88.    DisposeMovieController( theController );
  89.    theController = nil;
  90.    DisposeMovie( theMovie );
  91.    DisposeWindow( theWindow );
  92. }
  93.  
  94.  
  95. //____________________________________________________________
  96.  
  97. void  InitializeAllToolboxes( void )
  98. {
  99.    OSErr  theError;
  100.    long   theResult;
  101.  
  102.    InitGraf( &qd.thePort );
  103.    InitFonts();
  104.    InitWindows();
  105.    InitMenus();
  106.    TEInit();
  107.    InitDialogs( 0L );
  108.    FlushEvents( everyEvent, 0 );
  109.    InitCursor();
  110.  
  111.    theError = Gestalt( gestaltQuickTime, &theResult );
  112.    if ( theError != noErr )
  113.       ExitToShell();
  114.                                                  
  115.    theError = EnterMovies();  
  116.    if ( theError != noErr )
  117.       ExitToShell(); 
  118. }
  119.  
  120.  
  121.  
  122.